package org.lanqiao.userprofile.movie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.lanqiao.userprofile.movie.entity.OdsMovieInfo;
import org.lanqiao.userprofile.movie.mapper.OdsMovieInfoDao;
import org.lanqiao.userprofile.movie.service.OdsMovieInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author root
 * @since 2023-09-25
 */
@Service
public class OdsMovieInfoServiceImpl extends ServiceImpl<OdsMovieInfoDao, OdsMovieInfo> implements OdsMovieInfoService {

    @Override
    public List<OdsMovieInfo> selectTop() {
        return baseMapper.queryTop();
    }

    @Override
    public Page<OdsMovieInfo> selectPage(int current, int size, String tag) {
        LambdaQueryWrapper<OdsMovieInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(OdsMovieInfo::getTags, tag);

        Page<OdsMovieInfo> page = new Page<>(current, size);
        page.setOrders(Arrays.asList(OrderItem.asc("id")));
        return (Page<OdsMovieInfo>) baseMapper.selectPage(page, queryWrapper);
    }

    @Override
    public Page<OdsMovieInfo> selectPage(int current, int size) {
        Page<OdsMovieInfo> page = new Page<>(current, size);
        page.setOrders(Arrays.asList(OrderItem.desc("id")));
        return (Page<OdsMovieInfo>) baseMapper.selectPage(page, null);
    }

}
